import pycurl

class AbsynthModFTP:
    def connect(self, server, user, password):
        self.ftp.setopt(self.ftp.URL, "ftp://%s/" % server)
        self.ftp.setopt(self.ftp.FTP_USE_EPSV, 1)
        #self.ftp.setopt(c.USERPWD, '%s:%s' %user %password)
        self.ftp.perform()
    def disconnect(self):
        self.ftp.close()
    def cwd(self, path):
        self.ftp.setopt(c.CUSTOMREQUEST, "PWD %s" % path)
        self.ftp.perform()
    def pwd(self):
        pwdl = []
        ftp = self.ftp
        ftp.setopt(ftp.WRITEFUNCTION, pwdl.append)
        ftp.setopt(ftp.CUSTOMREQUEST, 'PWD')
        return str(pwdl)
    def welcome(self):
        return 'f'#self.ftp.getwelcome()
    def download(self, file):
        self.ftp.retrbinary('RETR' + file, self.ftp_file_printer_callback) 
    def list_dir(self):
        list = ''
        filename = []
        mtime = []
        ftp = self.ftp
        ftp.setopt(ftp.WRITEFUNCTION, list+line)
        ftp.setopt(ftp.CUSTOMREQUEST, 'LIST')
        ftp.perform()
        print list
        for item in list:
            word = item
            str(word)
            words = word.split('\n')
            if words[0][0] != 'd' and words[0][0] != 'l':
                continue
            filename.append(words[-1])
            mtime.append(words[5] + ' ' + words[6] + ' ' + words[7])
        return filename, mtime         
    def list_file(self):
        list = []
        filename = []
        size = []
        mtime = []
        ftp = self.ftp
        ftp.setopt(ftp.WRITEFUNCTION, list.append)
        ftp.setopt(ftp.CUSTOMREQUEST, 'LIST')
        ftp.perform()
        for item in list:
            word = item
            str(word)
            words = word.split('\n')
            if words[0][0] == 'd' or words[0][0] == 'l':
                continue
            filename.append(words[-1])
            size.append(words[4])
            mtime.append(words[5] + ' ' + words[6] + ' ' + words[7])
        return filename, size, mtime